package com.salesforce.dataloader.ui.uiActions;

import org.eclipse.jface.action.Action;

import com.salesforce.dataloader.action.OperationInfo;
import com.salesforce.dataloader.controller.Controller;
import com.salesforce.dataloader.ui.LoaderWindow;
import com.salesforce.dataloader.ui.LoaderWizardDialog;

public class OperationUIAction extends Action {
    private final Controller controller;
    private final OperationInfo opInfo;

    public OperationUIAction(Controller controller, OperationInfo info) {
        super(info.getMenuLabel(), info.getIconImageDescriptor());
        setToolTipText(info.getToolTipText());

        this.controller = controller;
        this.opInfo = info;

        setEnabled(info.isOperationAllowed(controller.getConfig()));
    }

    @Override
    public void run() {
        LoaderWizardDialog dlg = new LoaderWizardDialog(LoaderWindow.getApp().getShell(), this.opInfo
                .instantiateWizard(this.controller));
        dlg.open();
    }

}
